import ctypes
import platform

# 跨平台DPI适配
def setup_dpi_awareness():
    """设置DPI感知，支持Windows、macOS和Linux"""
    system = platform.system()
    
    if system == "Windows":
        try:
            # Windows 10 及以上版本
            ctypes.windll.shcore.SetProcessDpiAwareness(1)
            return ctypes.windll.shcore.GetScaleFactorForDevice(0) / 100
        except AttributeError:
            try:
                # Windows 8.1 及以下版本
                ctypes.windll.user32.SetProcessDPIAware()
                return 1.0
            except:
                return 1.0
    elif system == "Darwin":  # macOS
        return 1.0
    else:  # Linux 和其他系统
        return 1.0

# 获取缩放因子
ScaleFactor = setup_dpi_awareness()

# 应用DPI缩放
def apply_dpi_scaling(root):
    """应用DPI缩放，支持不同操作系统"""
    system = platform.system()
    
    if system == "Windows":
        try:
            # Windows系统使用tk缩放
            root.call('tk', 'scaling', ScaleFactor)
        except:
            # 如果失败，使用默认缩放
            pass
    else:
        # macOS和Linux通常不需要手动设置DPI缩放
        # 系统会自动处理
        pass

# 窗口配置
WINDOW_WIDTH = 1600
WINDOW_HEIGHT = 600
WINDOW_TITLE = "连锁软件设计"

# 区段配置
SECTIONS_CONFIG = {
    '5G': {'coords': (370, 150, 650, 150), 'text_pos': (510, 135), 'occupied': False, 'red_line': None},
    '6DG': {'coords': (650, 150, 900, 150), 'text_pos': (775, 135), 'occupied': False, 'red_line': None},
    '7G': {'coords': (900, 150, 1050, 150), 'text_pos': (975, 135), 'occupied': False, 'red_line': None},
    '8G': {'coords': (820, 450, 1100, 450), 'text_pos': (960, 465), 'occupied': False, 'red_line': None},
    '4DG': {'coords': (490, 450, 820, 450), 'text_pos': (655, 465), 'occupied': False, 'red_line': None},
    '4G': {'coords': (350, 300, 480, 300), 'text_pos': (415, 285), 'occupied': False, 'red_line': None},
    '2DG': {'coords': (480, 300, 700, 300), 'text_pos': (590, 285), 'occupied': False, 'red_line': None},
    '2G': {'coords': (100, 450, 490, 450), 'text_pos': (295, 465), 'occupied': False, 'red_line': None}
}

# 信号机通路配置
SIGNAL_PATHS = {
    ('F1', 'F3'): ['2G'],
    ('F1', 'F6'): ['2G', '4DG'],
    ('F1', 'SC'): ['2G', '4DG', '8G'],

    ('F2', 'F5'): ['4G'],
    ('F2', 'F6'): ['4G', '2DG', '4DG'],
    ('F2', 'SC'): ['4G', '2DG', '4DG', '8G'],
    ('F2', 'XC'): ['4G', '2DG'],
    ('F2', 'F8'): ['4G', '2DG', '7G'],

    ('F3', 'F6'): ['4DG'],
    ('F3', 'SC'): ['4DG', '8G'],

    ('F5', 'F6'): ['2DG', '4DG'],
    ('F5', 'SC'): ['2DG', '4DG', '8G'],
    ('F5', 'XC'): ['2DG'],
    ('F5', 'F8'): ['2DG', '7G'],

    ('F4', 'XC'): ['5G', '6DG'],
    ('F4', 'F8'): ['5G', '6DG', '7G'],

    ('XC', 'F8'): ['7G']
} 